home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-05-01 | 13.0 KB | 446 lines | [TEXT/MPCC] |
- //----------------------------------------------------------------------------------------
- // Imaging protocol
- //----------------------------------------------------------------------------------------
-
- #ifndef _CREDITNOWDEMO_
- #include "CPCreditNowDemo.h"
- #endif
-
- #ifndef __ICONS__
- #include <Icons.h>
- #endif
-
- #ifndef SOM_ODDispatcher_xh
- #include <Disptch.xh>
- #endif
-
- #if GENERATING68K
- #pragma segment Imaging
- #endif
-
- //----------------------------------------------------------------------------------------
-
- void CPCreditNowDemo::Draw(Environment* ev, ODFacet* facet, ODShape* invalidShape)
- {
- // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_Draw
- EnteringMethod("\pCPCreditNowDemo::Draw");
- ODUnused(invalidShape);
-
- CFocus foc(ev, facet);
-
- ODTypeToken view = facet->GetFrame(ev)->GetViewType(ev);
-
- if (view == fSession->Tokenize(ev, kODViewAsLargeIcon))
- {
- this->PrivDrawAsLargeIcon(ev, facet, invalidShape);
- return;
- }
-
- if (view == fSession->Tokenize(ev, kODViewAsSmallIcon))
- {
- this->PrivDrawAsSmallIcon(ev, facet, invalidShape);
- return;
- }
-
- if (view == fSession->Tokenize(ev, kODViewAsThumbnail))
- {
- this->PrivDrawAsThumbnail(ev, facet, invalidShape);
- return;
- }
-
- if (view == fSession->Tokenize(ev, kODViewAsFrame))
- {
- ODFrame* frame = facet->GetFrame(ev);
- ODShape* usedShape = frame->GetUsedShape(ev, kODNULL);
- RgnHandle rgn = usedShape->GetQDRegion(ev);
-
- usedShape->Release(ev);
-
- Rect rct = (*rgn)->rgnBBox;
- RgnHandle oldClip = NULL;
-
- if (frame->IsRoot(ev))
- {
- GrafPtr curPort;
-
- ::GetPort(&curPort);
- ::EraseRect(&(curPort->portRect));
- }
- else {
- ::EraseRoundRect(&rct, 40, 40);
- ::PenSize(3, 3);
- ::FrameRoundRect(&rct, 40, 40);
- ::PenNormal();
- }
-
- //AET<<
- // Draw all the text boxes, button, and our fancy PICTs
-
- for ( TextFieldLink *fl = fTextFields.First(); fl->GetTextField(); fl = fl->Next() )
- ( ((LabeledTextField*)fl->GetTextField()) )->Draw(rgn);
-
- fAddressVerify->Draw(rgn);
- fAuthorization->Draw(rgn);
-
- this->ShowNiceImages( ev, facet ); // rgacsun
-
- //Draw Button
- //assume the window origin is where it was when control was created (0,0)
- if (frame->IsRoot(ev))
- ::SetOrigin(0,0);
- ::PenSize(3, 3);
- Rect r = (**fAuthButton).contrlRect;
- ::InsetRect(&r, -4, -4);
- ::FrameRoundRect(&r,16, 16);
- ::PenNormal();
- ::Draw1Control(fAuthButton);
- //AET>>
-
- if (oldClip) {
- ::SetClip(oldClip);
- ::DisposeRgn(oldClip);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
-
- static pascal OSErr PrivDetachIconResource(ResType theType, Handle *theIcon, void* yourDataPtr)
- {
- if (theIcon != kODNULL && *theIcon != kODNULL)
- {
- ::DetachResource(*theIcon);
- return ::ResError();
- }
- else
- return noErr;
- }
-
- //----------------------------------------------------------------------------------------
-
- void CPCreditNowDemo::PrivDrawAsLargeIcon(Environment* ev, ODFacet* facet, ODShape* invalidShape)
- {
- Rect rect32;
- IconTransformType transformType = ttNone;
- Handle iconSuite;
-
- // Check to see if the icon is selected and in an active window
- if ( facet->GetHighlight(ev) == kODFullHighlight && facet->GetWindow(ev)->IsActive(ev) )
- transformType = ttSelected;
-
- // Draw the icon.
- {
- CUsingLibraryResources res;
- OSErr error = ::GetIconSuite(&iconSuite, kHelloIconSuite, svAllLargeData);
-
- if ( error == noErr )
- {
- // Create a universal proc pointer for our icon action proc.
- IconActionUPP actionProc = NewIconActionProc(PrivDetachIconResource);
- error = ::ForEachIconDo(iconSuite, svAllLargeData, actionProc, kODNULL);
- DisposeRoutineDescriptor(actionProc);
- }
- }
-
- ::SetRect(&rect32, 0, 0, kODLargeIconSize, kODLargeIconSize);
- ::PlotIconSuite(&rect32, atAbsoluteCenter, transformType, iconSuite);
-
- if ( facet->GetHighlight(ev) == kODDimHighlight )
- {
- ODShape* usedShape = facet->GetFrame(ev)->GetUsedShape(ev, kODNULL);
- RgnHandle usedRgn = usedShape->GetQDRegion(ev);
-
- ::PenPat(&ODQDGlobals.gray);
- ::FrameRgn(usedRgn);
- ::PenNormal();
-
- usedShape->Release(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
-
- void CPCreditNowDemo::PrivDrawAsSmallIcon(Environment* ev, ODFacet* facet, ODShape* invalidShape)
- {
- Rect rect16;
- IconTransformType transformType = ttNone;
- Handle iconSuite;
-
- // Check to see if the icon is selected and in an active window
- if ( facet->GetHighlight(ev) == kODFullHighlight && facet->GetWindow(ev)->IsActive(ev) )
- transformType = ttSelected;
-
- // Draw the icon.
- {
- CUsingLibraryResources res;
- OSErr error = ::GetIconSuite(&iconSuite, kHelloIconSuite, svAllSmallData);
-
- if ( error == noErr )
- {
- // Create a universal proc pointer for our icon action proc.
- IconActionUPP actionProc = NewIconActionProc(PrivDetachIconResource);
- error = ::ForEachIconDo(iconSuite, svAllLargeData, actionProc, kODNULL);
- DisposeRoutineDescriptor(actionProc);
- }
- }
-
- ::SetRect(&rect16, 0, 0, kODSmallIconSize, kODSmallIconSize);
- ::PlotIconSuite(&rect16, atAbsoluteCenter, transformType, iconSuite);
-
- if ( facet->GetHighlight(ev) == kODDimHighlight )
- {
- ODShape* usedShape = facet->GetFrame(ev)->GetUsedShape(ev, kODNULL);
- RgnHandle usedRgn = usedShape->GetQDRegion(ev);
-
- ::PenPat(&ODQDGlobals.gray);
- ::FrameRgn(usedRgn);
- ::PenNormal();
-
- usedShape->Release(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
-
- void CPCreditNowDemo::PrivDrawAsThumbnail(Environment* ev, ODFacet* facet, ODShape* invalidShape)
- {
- // The last image displayed as frame is used as a Thumbnail
- Rect rct;
- ::SetRect(&rct, 0, 0, kODThumbnailSize, kODThumbnailSize);
- if (fThumbnailPicture)
- ::DrawPicture(fThumbnailPicture, &rct);
- }
- //----------------------------------------------------------------------------------------
-
- void CPCreditNowDemo::CanvasUpdated(Environment* ev, ODCanvas* canvas)
- {
- // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_CanvasUpdated
- EnteringMethod("\pCPCreditNowDemo::CanvasUpdated");
- ODUnused(canvas);
- }
-
- //----------------------------------------------------------------------------------------
-
- void CPCreditNowDemo::HighlightChanged(Environment* ev, ODFacet* facet)
- {
- // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_HighlightChanged
- EnteringMethod("\pCPCreditNowDemo::HighlightChanged");
- ODUnused(facet);
- }
-
- //----------------------------------------------------------------------------------------
-
- ODULong CPCreditNowDemo::GetPrintResolution(Environment* ev, ODFrame* frame)
- {
- // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_GetPrintResolution
- EnteringMethod("\pCPCreditNowDemo::GetPrintResolution");
- ODUnused(frame);
- return 0;
- }
-
- //----------------------------------------------------------------------------------------
-
- void CPCreditNowDemo::FacetAdded(Environment* ev, ODFacet* facet)
- {
- // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_FacetAdded
- EnteringMethod("\pCPCreditNowDemo::FacetAdded");
-
- ODFrame* frame = facet->GetFrame(ev);
- frame->RequestFrameShape(ev, this->PrivGetFrameShape(ev, frame), kODNULL);
- // First, PrivGetFrameShape is called to calculate the frame
- // shape we want. However, we might not get it, due to the
- // needs/constraints of the containing part. Therefore, after
- // calculating what we want, we see if we can get it by calling
- // RequestFrameShape.
- // RequestFrameShape either returns us what we passed it, or
- // returns something else because it thinks it knows best.
- // Either way, we then proceed with the returned result.
- // Note that this means that we have to be prepared to deal
- // with a frame shape other than we desire.
-
- this->PrivAdjustFacets(ev, frame);
- // Given a new negotiated frame shape, adjust our facets based
- // on it. That's all there is to it.
-
- if (frame->IsRoot(ev))
- {
- ODBoolean succeeded = kODFalse;
- succeeded = fSession->GetArbitrator(ev)->RequestFocusSet(ev, fFocusSet,frame);
- if (succeeded)
- {
- this->FocusAcquired(ev, fSelectionFocus, frame);
- this->FocusAcquired(ev, fMenuFocus, frame);
- this->FocusAcquired(ev, fKeyFocus, frame);
- }
- }
- //AET<<
- {
- fFacet = facet;
- CFocus foc(ev, facet);
- this->CreateTextFields(ev);
-
- this->CreateButton(ev, facet);
-
- //tell it the part, a frame(optional), idle frequency
- ( fSession->GetDispatcher(ev) )->RegisterIdle(ev, fSelf, kODNULL, 1);
- (fCurrentField->GetTextField())->Activate();
-
- }
- //AET>>
- }
-
- //----------------------------------------------------------------------------------------
-
- void CPCreditNowDemo::FacetRemoved(Environment* ev, ODFacet* facet)
- {
- // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_FacetRemoved
- EnteringMethod("\pCPCreditNowDemo::FacetRemoved");
- }
-
- //----------------------------------------------------------------------------------------
-
- void CPCreditNowDemo::CanvasChanged(Environment* ev, ODFacet* facet)
- {
- // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_CanvasChanged
- EnteringMethod("\pCPCreditNowDemo::CanvasChanged");
- ODUnused(facet);
- }
-
- //----------------------------------------------------------------------------------------
-
- void CPCreditNowDemo::GeometryChanged(Environment* ev, ODFacet* facet,
- ODBoolean clipShapeChanged,
- ODBoolean externalTransformChanged)
- {
- // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_GeometryChanged
- EnteringMethod("\pCPCreditNowDemo::GeometryChanged");
- ODUnused(facet);
- ODUnused(clipShapeChanged);
- ODUnused(externalTransformChanged);
- }
-
-
-
-
- //AET<<
- //----------------------------------------------------------------------------------------
- // CPCreditNowDemo::CreateTextFields
- //----------------------------------------------------------------------------------------
-
- void CPCreditNowDemo::CreateTextFields(Environment* ev)
- {
- ODTypeToken aToken;
- Rect aRect;
-
- // Text Output Fields
-
- aToken = fSession->Tokenize(ev, kAuthorizationTextField);
- SetRect(&aRect,10,170,310,190); // rgacsat
- fAuthorization = new LabeledTextField();
- fAuthorization->InitTextField(aToken, 60, 100, &aRect, "\pAuthorization ");
-
- aToken = fSession->Tokenize(ev, kAddressVerificationTextField);
- SetRect(&aRect,10,146,310,166); // rgacsat
- fAddressVerify = new LabeledTextField();
- fAddressVerify->InitTextField(aToken, 60, 100, &aRect, "\pResult ");
-
- // Input fields
- // fields must be created in reverse order that you want them in the list
- // last field created is first field in list.
- aToken = fSession->Tokenize(ev, kAmountTextField); // 6
- SetRect(&aRect,175,112,310,132);
- fTextFields.Add(aToken, 20, 70, &aRect, "\pAmount $:");
-
- aToken = fSession->Tokenize(ev, kExpirationTextField); // 5
- SetRect(&aRect,10,112,160,132);
- fTextFields.Add(aToken, 5, 100, &aRect, "\pExpiration:");
-
- aToken = fSession->Tokenize(ev, kCreditNumberTextField); // 4
- SetRect(&aRect,10,88,310,108);
- fTextFields.Add(aToken, 19, 100, &aRect, "\pCredit Card:");
-
- aToken = fSession->Tokenize(ev, kCSZTextField); // 3
- SetRect(&aRect,10,64,310,84);
- fTextFields.Add(aToken, 100, 100, &aRect, "\pCity, State Zip:");
-
- aToken = fSession->Tokenize(ev, kAddressTextField); // 2
- SetRect(&aRect,10,40,310,60);
- fTextFields.Add(aToken, 100, 100, &aRect, "\pAddress:");
-
- aToken = fSession->Tokenize(ev, kNameTextField); // 1
- SetRect(&aRect,10,16,310,36);
- fTextFields.Add(aToken, 60, 100, &aRect, "\pName:");
-
- fCurrentField = fTextFields.First();
-
- // see CreateButton for Button creation
- }
- //AET>>
-
-
- //AET<<
- //----------------------------------------------------------------------------------------
- // CPCreditNowDemo::CreateButton
- //----------------------------------------------------------------------------------------
-
- void CPCreditNowDemo::CreateButton(Environment* ev, ODFacet *facet)
- {
- ODWindow* window = facet->GetWindow(ev);
- ODFrame* frame = facet->GetFrame(ev);
- if (kODNULL == fAuthButton)
- {
- WindowPtr wnd = window->GetPlatformWindow(ev);
- Rect r;
- if (frame->IsRoot(ev))
- ::SetOrigin(0,0);
- ::SetRect(&r, 220, 217, 302, 237);
- fAuthButton = ::NewControl(wnd, &r, "\pAuthorize", true, 0, 0, 0, pushButProc, 0);
- }
- if (frame->IsRoot(ev))
- ::SetOrigin(0,0);
- ::ShowControl(fAuthButton);
- }
- //AET>>
-
- //RGACSUN>>
- void CPCreditNowDemo::ShowNiceImages( Environment* ev, ODFacet *facet )
- {
- Rect aRect;
- PicHandle hPic = nil;
-
- ODWindow* window = facet->GetWindow(ev);
- ODFrame* frame = facet->GetFrame(ev);
-
- if (frame->IsRoot(ev))
- ::SetOrigin(0,0);
-
- // Draw thick/think line in middle of screen.
- ::PenSize(2, 2);
- ::MoveTo( 5, 138 );
- ::LineTo( 308, 138 ); // heavy upper line
- ::PenNormal();
- ::MoveTo( 5, 141 );
- ::LineTo( 309, 141 ); // light lower line
-
- // Draw an outline around the image area.
- // 0, 0, 209, 48
- ::SetRect( &aRect, 7, 200, 216, 248); // left, top, right, bottom
-
- // Get the image to display
- {
- CUsingLibraryResources fil;
- hPic = (PicHandle)GetResource( 'PICT', 1128 );
- if( nil != hPic )
- ::DetachResource((Handle)hPic); // Must detach it!
- }
-
- if( nil != hPic )
- {
- HLock( (Handle)hPic );
- DrawPicture( hPic, &aRect ); // same rectangle as the outline above.
- HUnlock( (Handle)hPic );
- }
- }
- //RGACSUN>>
-
-